package com.dsteiner.xelavos.client;

import java.beans.PropertyChangeListener;

import com.dsteiner.widgets.client.PropertyChangeCollection;
import com.dsteiner.widgets.client.Widgets.FlowPanelExt;
import com.dsteiner.widgets.client.Widgets.InlineHTMLExt;
import com.dsteiner.widgets.client.Widgets.LazyWidget;
import com.dsteiner.widgets.client.event.EventManagerImpl;
import com.dsteiner.xelavos.client.controller.SearchInfoController;
import com.dsteiner.xelavos.client.model.MainTabModel;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Widget;

public class SearchInfoWidget extends LazyWidget {

	public static class SearchInfoModel {
		private PropertyChangeCollection propertyChangeSupport = new PropertyChangeCollection(this);

		public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
			propertyChangeSupport.registerPropertyChangeListener(propertyName, listener);
		}
	}

	private SearchInfoController searchInfoController = new SearchInfoController();
	private final SearchInfoModel searchInfoModel;
	private final MainTabModel mainTabModel;

	public SearchInfoWidget(SearchInfoModel searchInfoModel, MainTabModel mainTabModel) {
		this.searchInfoModel = searchInfoModel;
		this.mainTabModel = mainTabModel;
	}

	@Override
	public Widget createContentWidget() {
		FlowPanel mainPanel = new FlowPanel();
		FlowPanelExt tabsSearchPanel = new FlowPanelExt();
		FlowPanelExt suggestionsPanel = new FlowPanelExt();
		InlineHTMLExt tabsSearchInfoHtml = new InlineHTMLExt();
		InlineHTMLExt suggestionsInfoHtml = new InlineHTMLExt();
		FlowPanelExt tabsSearchContentPanel = new FlowPanelExt();
		FlowPanelExt suggestionsContentPanel = new FlowPanelExt();
		FlowPanelExt wordsSuggestionsPanel = new FlowPanelExt();
		
		tabsSearchPanel.add((Widget)tabsSearchInfoHtml);
		tabsSearchPanel.add((Widget)tabsSearchContentPanel);
		
		suggestionsPanel.add((Widget)suggestionsInfoHtml);
		suggestionsPanel.add((Widget)suggestionsContentPanel);
		
		HTML html = new HTML("<h3>Porque no encontró nada</h3>");
		mainPanel.add(html);
		mainPanel.add(tabsSearchPanel);
		mainPanel.add(suggestionsPanel);
		mainPanel.add(wordsSuggestionsPanel);
		
		searchInfoController.registerEventManager(EventManagerImpl.getInstance());
		searchInfoController.registerSearchInfoWidget(this);
		searchInfoController.registerMainTabModel(mainTabModel);
		searchInfoController.registerSearchInfoModel(searchInfoModel);
		searchInfoController.registerTabsSearchContentPanel(tabsSearchContentPanel);
		searchInfoController.registerTabsSearchInfoHtml(tabsSearchInfoHtml);
		searchInfoController.registerTabsSearchPanel(tabsSearchPanel);
		searchInfoController.registerSuggestionsContentPanel(suggestionsContentPanel);
		searchInfoController.registerSuggestionsInfoHtml(suggestionsInfoHtml);
		searchInfoController.registerSuggestionsPanel(suggestionsPanel);
		searchInfoController.registerWordSuggestionsPanel(wordsSuggestionsPanel);
		return mainPanel;
	}

}
